<!-- 注意这里不需要写`<html><body>`这些东西，它是一个html片段，不是完整的html页面 -->
<form id="addOrUpdateForm" lay-filter="addOrUpdateForm" class="layui-form model-form">
    <div class="layui-col-md12">
        <fieldset class="layui-elem-field layui-field-title">
            <legend>基本信息</legend>
        </fieldset>
    </div>
    <div class="layui-col-md6">
        <input name="id" type="hidden"/>
        <div class="layui-form-item">
            <label class="layui-form-label layui-form-required">账号</label>
            <div class="layui-input-block">
                <input name="account" class="layui-input" placeholder="请输入账号" lay-verType="tips"
                       lay-verify="required" required/>
            </div>
        </div>
        <div id="passwordFormItemBox" class="layui-form-item" hidden>
            <label class="layui-form-label layui-form-required">密码</label>
            <div class="layui-input-block">
                <input name="password" type="password" class="layui-input" placeholder="请输入密码" lay-verType="tips"
                       lay-verify="required|psw" required/>
            </div>
        </div>
        <!--<div class="layui-form-item">
            <label class="layui-form-label">昵称</label>
            <div class="layui-input-block">
                <input name="nickName" class="layui-input" placeholder="请输入昵称"/>
            </div>
        </div>-->
        <div class="layui-form-item">
            <label class="layui-form-label layui-form-required">性别</label>
            <div class="layui-input-block">
                <div id="sexBox"></div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label layui-form-required">手机号</label>
            <div class="layui-input-block">
                <input name="phone" class="layui-input" placeholder="请输入手机号" lay-verType="tips"
                       lay-verify="required|phoneX" required maxlength="11"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">身份证号</label>
            <div class="layui-input-block">
                <input name="idNumber" class="layui-input" placeholder="请输入身份证号" maxlength="18"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">籍贯</label>
            <div class="layui-input-block">
                <input name="nativePlace" class="layui-input" placeholder="请输入籍贯"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">政治面貌</label>
            <div class="layui-input-block">
                <input name="politicalOutlook" class="layui-input" placeholder="请输入政治面貌"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">学校</label>
            <div class="layui-input-block">
                <input name="school" class="layui-input" placeholder="请输入学校"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">毕业院校</label>
            <div class="layui-input-block">
                <input name="graduateschool" class="layui-input" placeholder="请输入毕业院校"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">职务层级</label>
            <div class="layui-input-block">
                <input name="duties" class="layui-input" placeholder="请输入职务层级"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">军衔</label>
            <div class="layui-input-block">
                <input name="rank" class="layui-input" placeholder="请输入军衔"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">入伍时间</label>
            <div class="layui-input-block">
                <input id="rwTime" name="rwtime" placeholder="请选择入伍时间" autocomplete="off"
                       class="layui-input date-icon"/>
            </div>
        </div>
        <!--<div class="layui-form-item">
            <label class="layui-form-label">入学日期</label>
            <div class="layui-input-block">
                <input id="entryDayBox" name="entryDay" placeholder="请选择入职日期" autocomplete="off"
                       class="layui-input date-icon"/>
            </div>
        </div>-->
        <div class="layui-form-item">
            <label class="layui-form-label">培训层次</label>
            <div class="layui-input-block">
                <input  name="leveltrain" class="layui-input" placeholder="请输入培训层次"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">毕业时间</label>
            <div class="layui-input-block">
                <input id="graduationtime" name="graduationtime" placeholder="请选择毕业时间" autocomplete="off"
                       class="layui-input date-icon"/>
            </div>
        </div>
    </div>

    <div class="layui-col-md6">
        <div class="layui-form-item">
            <label class="layui-form-label layui-form-required">姓名</label>
            <div class="layui-input-block">
                <input name="name" class="layui-input" placeholder="请输入姓名" lay-verType="tips" lay-verify="required"
                       required/>
            </div>
        </div>
        <div id="rePasswordFormItemBox" class="layui-form-item" hidden>
            <label class="layui-form-label layui-form-required">重复密码</label>
            <div class="layui-input-block">
                <input name="rePassword" type="password" class="layui-input" placeholder="请输入重复密码"
                       lay-verType="tips"
                       lay-verify="required|equalTo" lay-equalTo="input[name=password]" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">出生年月</label>
            <div class="layui-input-block">
                <input id="birthdayBox" name="birthday" placeholder="请选择日期" autocomplete="off"
                       class="layui-input date-icon"/>
            </div>
        </div>
       <!-- <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-block">
                <input name="email" class="layui-input" placeholder="请输入邮箱" lay-verType="tips"
                       lay-verify="emailX"/>
            </div>
        </div>-->
        <div class="layui-form-item">
            <label class="layui-form-label">电话</label>
            <div class="layui-input-block">
                <input name="tel" class="layui-input" placeholder="请输入电话" maxlength="11"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">学号</label>
            <div class="layui-input-block">
                <input name="stuNumber" class="layui-input" placeholder="请输入学号" maxlength="18"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">民族</label>
            <div class="layui-input-block">
                <input name="nation" class="layui-input" placeholder="请输入民族"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">学习专业</label>
            <div class="layui-input-block">
                <input name="aftermajor" class="layui-input" placeholder="请输入专业"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">学历</label>
            <div class="layui-input-block">
                <input name="education" class="layui-input" placeholder="请输入学历"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">层级时间</label>
            <div class="layui-input-block">
                <input id="dutiestime" name="dutiestime" class="layui-input date-icon" autocomplete="off"
                       placeholder="请输入职务层级时间"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">军衔时间</label>
            <div class="layui-input-block">
                <input id="ranktime" name="ranktime" class="layui-input date-icon"
                       placeholder="请输入军衔时间" autocomplete="off"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">入学前单位</label>
            <div class="layui-input-block">
                <input id="entryUnit" name="entryunit" placeholder="请选择入职前单位"
                       class="layui-input"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">入学后单位</label>
            <div class="layui-input-block">
                <input id="unit" name="unit" placeholder="请选择入职后单位"
                       class="layui-input"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">入学时间</label>
            <div class="layui-input-block">
                <input id="enroltime" name="enroltime" placeholder="请选择入学时间"
                       class="layui-input date-icon" autocomplete="off"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">学制</label>
            <div class="layui-input-block">
                <input id="educationsystem" name="educationsystem" placeholder="请输入学制"
                       class="layui-input"/>
            </div>
        </div>
    </div>

    <div class="layui-col-md12">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>员工信息</legend>
        </fieldset>
    </div>
    <div class="layui-col-md6">
        <div class="layui-form-item">
            <label class="layui-form-label layui-form-required">机构</label>
            <div class="layui-input-block">
                <div id="orgSelectBox" class="ew-xmselect-tree"></div>
            </div>
        </div>
    </div>
    <div class="layui-col-md6">
        <div class="layui-form-item">
            <label class="layui-form-label">工号</label>
            <div class="layui-input-block">
                <input id="jobNumInputBox" name="sysEmpParam.jobNum" class="layui-input" placeholder="请输入工号"/>
            </div>
        </div>
    </div>
    <div class="layui-col-md12">
        <div class="layui-form-item">
            <label class="layui-form-label layui-form-required">职位</label>
            <div class="layui-input-block">
                <div id="posIdListBox"></div>
            </div>
        </div>
    </div>
    <div class="layui-col-md12">
        <div class="layui-form-item">
            <label class="layui-form-label">附属信息</label>
            <button class="layui-btn layui-btn-sm icon-btn" id="extAddButton" type="button">
                <i class="layui-icon">&#xe654;</i>添加信息
            </button>
            <div class="layui-input-block">
                <table id="extTable" lay-filter="extTable"></table>
            </div>
        </div>
    </div>

    <!--<div class="layui-col-md12" id="activity">
        <div class="layui-form-item">
            <label class="layui-form-label">大项活动</label>
            <button class="layui-btn layui-btn-sm icon-btn" id="activityAddButton" type="button">
                <i class="layui-icon">&#xe654;</i>添加活动
            </button>
            <button class="layui-btn layui-btn-sm icon-btn" id="importActivity" type="button">
                <i class="layui-icon">&#xe681;</i>导入
            </button>
            <div class="layui-input-block">
                <table id="activityTable" lay-filter="activityTable"></table>
            </div>
        </div>
    </div>
    <div class="layui-col-md12" id="stuExperience">
        <div class="layui-form-item">
            <label class="layui-form-label">学习经历</label>
            <button class="layui-btn layui-btn-sm icon-btn" id="stuAddButton" type="button">
                <i class="layui-icon">&#xe654;</i>添加学习经历
            </button>
            <button class="layui-btn layui-btn-sm icon-btn" id="importStudy" type="button">
                <i class="layui-icon">&#xe681;</i>导入
            </button>
            <div class="layui-input-block">
                <table id="stuTable" lay-filter="stuTable"></table>
            </div>
        </div>
    </div>
    <div class="layui-col-md12" id="scoreExperience">
        <div class="layui-form-item">
            <label class="layui-form-label">训练成绩</label>
            <button class="layui-btn layui-btn-sm icon-btn" id="scoreAddButton" type="button">
                <i class="layui-icon">&#xe654;</i>添加科目和成绩
            </button>
            <button class="layui-btn layui-btn-sm icon-btn" id="importTrain" type="button">
                <i class="layui-icon">&#xe681;</i>导入
            </button>
            <div class="layui-input-block">
                <table id="scoreTable" lay-filter="scoreTable"></table>
            </div>
        </div>
    </div>
    <div class="layui-col-md12" id="merExperience">
        <div class="layui-form-item">
            <label class="layui-form-label">立功授奖</label>
            <button class="layui-btn layui-btn-sm icon-btn" id="merAddButton" type="button">
                <i class="layui-icon">&#xe654;</i>添加立功经历
            </button>
            <button class="layui-btn layui-btn-sm icon-btn" id="importMer" type="button">
                <i class="layui-icon">&#xe681;</i>导入
            </button>
            <div class="layui-input-block">
                <table id="merTable" lay-filter="merTable"></table>
            </div>
        </div>
    </div>
    <div class="layui-col-md12" id="jobExperience">
        <div class="layui-form-item">
            <label class="layui-form-label">工作经历</label>
            <button class="layui-btn layui-btn-sm icon-btn" id="jobAddButton" type="button">
                <i class="layui-icon">&#xe654;</i>添加工作经历
            </button>
            <button class="layui-btn layui-btn-sm icon-btn" id="importWork" type="button">
                <i class="layui-icon">&#xe681;</i>导入
            </button>
            <div class="layui-input-block">
                <table id="jobTable" lay-filter="jobTable"></table>
            </div>
        </div>
    </div>
-->
    <div class="layui-col-md12" style="margin-bottom: 20px;">
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="formSubmitBtn" lay-submit>保存</button>
        </div>
    </div>
</form>

<!-- 表格操作列 -->
<script type="text/html" id="extTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="extEdit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="extDelete">删除</a>
</script>
<!-- 学习培训成绩表格操作列 -->
<!--<script type="text/html" id="scoreTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="scoreEdit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="scoreDelete">删除</a>
</script>
&lt;!&ndash; 大项活动表格操作列 &ndash;&gt;
<script type="text/html" id="activityTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="activityEdit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="activityDelete">删除</a>
</script>

&lt;!&ndash; 学习经历表格操作列 &ndash;&gt;
<script type="text/html" id="stuTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="stuEdit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="stuDelete">删除</a>
</script>
&lt;!&ndash; 立功经历表格操作列 &ndash;&gt;
<script type="text/html" id="merTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="merEdit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="merDelete">删除</a>
</script>
&lt;!&ndash; 工作经历表格操作列 &ndash;&gt;
<script type="text/html" id="jobTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="jobEdit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="jobDelete">删除</a>
</script>-->


<script>
    layui.use(['layer', 'form', 'admin', 'table', 'tableX', 'xnUtil', 'xmSelect', 'laydate', 'upload'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var tableX = layui.tableX;
        var admin = layui.admin;
        var xnUtil = layui.xnUtil;
        var xmSelect = layui.xmSelect;
        var laydate = layui.laydate;
        var upload = layui.upload;



        var editData = admin.getLayerData('#addOrUpdateForm').data;

        var orgTreeRenderIns = {};
        admin.req(getProjectUrl() + 'sysOrg/tree', function (res) {
            // 渲染下拉树
            orgTreeRenderIns = xmSelect.render({
                el: '#orgSelectBox',
                name: 'sysEmpParam.orgId',
                height: '250px',
                layVerify: 'required',
                layVerType: 'tips',
                data: res.data,
                initValue: editData ? (editData.sysEmpInfo ? (editData.sysEmpInfo.orgId ? [editData.sysEmpInfo.orgId] : []) : []) : [],
                model: {label: {type: 'text'}},
                prop: {
                    name: 'title',
                    value: 'id'
                },
                radio: true,
                clickClose: true,
                tree: {
                    show: true,
                    indent: 15,
                    strict: false,
                    expandedKeys: true
                },
                tips: '请选择机构'
            });
        }, {async: false});

        //渲染日期组件
        laydate.render({elem: '#birthdayBox', trigger: 'click'});// 生日
        laydate.render({elem: '#entryDayBox', trigger: 'click'});// 入职日期
        laydate.render({elem: '#rwTime', trigger: 'click'});// 入伍时间

        laydate.render({elem: '#dutiestime', trigger: 'click'});// 生日
        laydate.render({elem: '#ranktime', trigger: 'click'});// 入职日期
        laydate.render({elem: '#enroltime', trigger: 'click'});// 入伍时间
        laydate.render({elem: '#graduationtime', trigger: 'click'});// 入伍时间

        // 渲染字典下拉
        var sexDataRenderIns = xmSelect.render({
            el: '#sexBox',
            name: 'sex',
            data: xnUtil.getDictDataByDictTypeCode('sex', null),
            layVerify: 'required',
            layVerType: 'tips',
            radio: true,
            clickClose: true,
            model: {icon: 'hidden', label: {type: 'text'}},
            prop: {
                name: 'name',
                value: 'code'
            },
            tips: '请选择性别'
        });


        // 渲染远程数据下拉
        var remoteDataRenderIns = {};
        admin.req(getProjectUrl() + 'sysPos/list', function (res) {
            remoteDataRenderIns = xmSelect.render({
                el: '#posIdListBox',
                name: 'sysEmpParam.posIdList',
                data: res.data,
                layVerify: 'required',
                layVerType: 'tips',
                radio: false,
                prop: {
                    name: 'name',
                    value: 'id'
                },
                tips: '请选择职位'
            });
        }, {async: false});


        /** ************************************** 附属信息相关 *************************************** **/
        /* 渲染表格 */
        var extTableData = [];
        var insExtTb = tableX.render({
            elem: '#extTable',
            data: [],
            page: false,
            defaultToolbar: [],
            cellMinWidth: 100,
            cols: [
                [
                    {field: 'orgId', title: 'orgId', hide: true},
                    {field: 'posId', title: 'posId', hide: true},
                    {field: 'orgName', title: '机构名称'},
                    {field: 'posName', title: '职位名称'},
                    {title: '操作', toolbar: '#extTableBar', align: 'center', width: 200, minWidth: 200}
                ]
            ],
            done: function (res, curr, count) {
                xnUtil.tableDone(insExtTb, res, curr, count);
            }
        });

        /* 表格工具条点击事件 */
        table.on('tool(extTable)', function (obj) {
            /* 删除 */
            if (obj.event === 'extDelete') {
                for (var i = 0; i < extTableData.length; i++) {
                    if (extTableData[i].orgId === obj.data.orgId && extTableData[i].posId === obj.data.posId) {
                        extTableData.splice(i, 1);
                    }
                }
                insExtTb.reload({data: extTableData});
            }
            /* 编辑 */
            if (obj.event === 'extEdit') {
                showExtOrgPosAddOrUpdateModel(obj.data);
            }
        });

        /* 添加附属信息点击事件 */
        $('#extAddButton').click(function () {
            showExtOrgPosAddOrUpdateModel();
        });

        // 显示表单弹窗
        function showExtOrgPosAddOrUpdateModel(data) {
            var layIndex = admin.open({
                offset: '150px',
                title: (data ? '修改' : '添加') + '附属信息',
                url: getProjectUrl() + 'sysUser/extForm',
                data: {data: data},     // 传递数据到表单页面
                end: function () {
                    var layerData = admin.getLayerData(layIndex, 'formOk');
                    if (layerData) {  // 判断表单操作成功标识
                        var resultData = admin.getLayerData(layIndex, 'resultData');
                        if (data) {
                            for (var i = 0; i < extTableData.length; i++) {
                                if (extTableData[i].orgId === data.orgId && extTableData[i].posId === data.posId) {
                                    extTableData.splice(i, 1, resultData);
                                }
                            }
                        } else {
                            extTableData.push(resultData);
                        }

                        insExtTb.reload({data: extTableData}); // 成功刷新表格
                    }
                },
                success: function (layero, dIndex) {
                    // 弹窗超出范围不出现滚动条
                    $(layero).children('.layui-layer-content').css('overflow', 'visible');
                    $(layero).find('[lay-submit]').focus();
                }
            });
        }

        /** ************************************** 附属信息相关 *************************************** **/

        /** ************************************** 大项活动相关 *************************************** **/
        /* 渲染大项活动信息表格 */
       /* var activityInsTb = tableX.render({
            elem: '#activityTable',
            url: getProjectUrl() + 'sysUserActivity/page' + (editData ? '?userId=' + editData.id : ''),
            page: true,
            defaultToolbar: [],
            cellMinWidth: 100,
            cols: [
                [
                    {type: 'checkbox'},
                    {field: 'activityTitle', title: '活动标题', sort: true, align: 'center', minWidth: 145},
                    {field: 'activityContent', title: '活动内容', sort: true, minWidth: 230},
                    {field: 'activityTime', title: '活动时间', sort: true, align: 'center', minWidth: 145},
                    {
                        field: 'status',
                        title: '状态',
                        sort: true,
                        align: 'center',
                        minWidth: 145,
                        templet: function (d) {
                            return xnUtil.rendDataTableDict(d.status, 'common_status');
                        }
                    },
                    {field: 'remark', title: '备注', sort: true, align: 'center', minWidth: 145},
                    {title: '操作', toolbar: '#activityTableBar', align: 'center', width: 160, minWidth: 160}
                ]
            ],
            done: function (res, curr, count) {
                console.log(res);
                console.log(curr);
                console.log(count);
                xnUtil.tableDone(activityInsTb, res, curr, count);
            }
        });
        var userIds = "";
        if(editData != undefined){
            userIds = editData.id;
        }
        // 活动上传
        debugger;
        upload.render({
            elem: '#importActivity',
            url: getProjectUrl() + 'sysUserInfo/uploadActive?flag=0&userId='+userIds,
            accept: 'file',
            exts: 'xls|xlsx',
            done: function (res) {
                debugger;
                handleNetworkError(res);
                if (res.success) {
                    layer.msg(res.message, {icon: 1, time: 1000}, function () {
                        activityInsTb.reload();
                    });
                }
            }
        });
        /!* 大项活动信息表格工具条点击事件 *!/
        table.on('tool(activityTable)', function (obj) {
            /!* 删除 *!/
            if (obj.event === 'activityDelete') {
                layer.confirm('确定要操作该数据吗？', {
                    skin: 'layui-layer-admin',
                    shade: .1
                }, function () {
                    admin.req(getProjectUrl() + 'sysUserActivity/delete', JSON.stringify([{'id': obj.data.id}]), function (res) {
                        layer.msg(res.message, {icon: 1, time: 1000}, function () {
                            activityInsTb.reload();
                        });
                    }, 'post');
                });
            }
            /!* 编辑 *!/
            if (obj.event === 'activityEdit') {
                showActivityAddOrUpdateModel(obj.data);
            }
        });

        /!* 添加大项活动信息点击事件 *!/
        $('#activityAddButton').click(function () {
            showActivityAddOrUpdateModel();
            admin.putTempData('formUserId', editData.id);
        });

        // 显示表单弹窗
        function showActivityAddOrUpdateModel(data) {
            var layIndex = admin.open({
                title: (data ? '修改' : '添加') + '用户大项活动表',
                url: getProjectUrl() + 'sysUser/activityForm',
                area: ['800px', ''],
                data: {data: data},     // 传递数据到表单页面
                end: function () {
                    var layerData = admin.getLayerData(layIndex, 'formOk');
                    if (layerData) {  // 判断表单操作成功标识
                        activityInsTb.reload();  // 成功刷新表格
                    }
                },
                success: function (layero, dIndex) {
                    // 弹窗超出范围不出现滚动条
                    $(layero).children('.layui-layer-content').css('overflow', 'visible');
                    $(layero).find('[lay-submit]').focus();
                }
            });
        }

        /!** ************************************** 大项活动相关 *************************************** **!/


        /!** ************************************** 学习经历相关 *************************************** *!/
        /!* 渲染学习经历信息表格 *!/
        var stuInsTb = tableX.render({
            elem: '#stuTable',
            url: getProjectUrl() + 'sysUserStudyExperience/page' + (editData ? '?userId=' + editData.id : ''),
            page: true,
            defaultToolbar: [],
            cellMinWidth: 100,
            cols: [
                [
                    {type: 'checkbox'},
                    {field: 'studyTitle', title: '学习标题', sort: true, align: 'center', minWidth: 125},
                    {field: 'studyContent', title: '学习内容', sort: true, minWidth: 200},
                    {field: 'studyTime', title: '学习时间', sort: true, align: 'center', minWidth: 125},
                    {
                        field: 'studyDuration',
                        title: '学习时长',
                        sort: true,
                        align: 'center',
                        minWidth: 110,
                        templet: function (d) {
                            return d.studyDuration + "年";
                        }
                    },
                    {
                        field: 'status',
                        title: '状态',
                        sort: true,
                        align: 'center',
                        minWidth: 125,
                        templet: function (d) {
                            return xnUtil.rendDataTableDict(d.status, 'common_status');
                        }
                    },
                    {field: 'remark', title: '备注', sort: true, align: 'center', minWidth: 125},
                    {title: '操作', toolbar: '#stuTableBar', align: 'center', width: 180, minWidth: 180}
                ]
            ],
            done: function (res, curr, count) {
                xnUtil.tableDone(stuInsTb, res, curr, count);
            }
        });
       // 学习经历
        upload.render({
            elem: '#importStudy',
            url: getProjectUrl() + 'sysUserInfo/uploadActive?flag=1&userId='+userIds,
            accept: 'file',
            exts: 'xls|xlsx',
            done: function (res) {
                debugger;
                handleNetworkError(res);
                if (res.success) {
                    layer.msg(res.message, {icon: 1, time: 1000}, function () {
                        activityInsTb.reload();
                    });
                }
            }
        });
        /!* 学习经历信息表格工具条点击事件 *!/
        table.on('tool(stuTable)', function (obj) {
            /!* 删除 *!/
            if (obj.event === 'stuDelete') {
                layer.confirm('确定要操作该数据吗？', {
                    skin: 'layui-layer-admin',
                    shade: .1
                }, function () {
                    admin.req(getProjectUrl() + 'sysUserStudyExperience/delete', JSON.stringify([{'id': obj.data.id}]), function (res) {
                        layer.msg(res.message, {icon: 1, time: 1000}, function () {
                            stuInsTb.reload();
                        });
                    }, 'post');
                });
            }
            /!* 编辑 *!/
            if (obj.event === 'stuEdit') {
                showStuAddOrUpdateModel(obj.data);
            }
        });

        /!* 添加学习经历信息点击事件 *!/
        $('#stuAddButton').click(function () {
            showStuAddOrUpdateModel();
            admin.putTempData('formUserId', editData.id);
        });

        // 显示表单弹窗
        function showStuAddOrUpdateModel(data) {
            var layIndex = admin.open({
                title: (data ? '修改' : '添加') + '用户学习经历表',
                url: getProjectUrl() + 'sysUser/stuForm',
                area: ['800px', ''],
                data: {data: data},     // 传递数据到表单页面
                end: function () {
                    var layerData = admin.getLayerData(layIndex, 'formOk');
                    if (layerData) {  // 判断表单操作成功标识
                        stuInsTb.reload();  // 成功刷新表格
                    }
                },
                success: function (layero, dIndex) {
                    // 弹窗超出范围不出现滚动条
                    $(layero).children('.layui-layer-content').css('overflow', 'visible');
                    $(layero).find('[lay-submit]').focus();
                }
            });
        }

        /!** ************************************** 学习经历相关 *************************************** **!/

        /!** ************************************** 学习培训成绩相关 *************************************** **!/
        /!* 渲染表格 *!/
        var scoreInsTb = tableX.render({
            elem: '#scoreTable',
            url: getProjectUrl() + 'sysUserStuScore/page' + (editData ? '?userId=' + editData.id : ''),
            page: true,
            defaultToolbar: [],
            cellMinWidth: 100,
            cols: [
                [
                    {type: 'checkbox'},
                    // {field: 'yearTime', title: '培训年份', sort: true},
                    {field: 'name', title: '科目名称', sort: true},
                    {field: 'score', title: '科目成绩', sort: true},
                    {field: 'trainTime', title: '训练时间', sort: true},
                    {field: 'remark', title: '备注', sort: true},
                    {title: '操作', toolbar: '#scoreTableBar', align: 'center', width: 200, minWidth: 200}
                ]
            ],
            done: function (res, curr, count) {
                xnUtil.tableDone(scoreInsTb, res, curr, count);
            }
        });
       // 训练成绩
        upload.render({
            elem: '#importTrain',
            url: getProjectUrl() + 'sysUserInfo/uploadActive?flag=2&userId='+userIds,
            accept: 'file',
            exts: 'xls|xlsx',
            done: function (res) {
                debugger;
                handleNetworkError(res);
                if (res.success) {
                    layer.msg(res.message, {icon: 1, time: 1000}, function () {
                        activityInsTb.reload();
                    });
                }
            }
        });
        /!* 表格工具条点击事件 *!/
        table.on('tool(scoreTable)', function (obj) {
            /!* 删除 *!/
            if (obj.event === 'scoreDelete') {
                layer.confirm('确定要操作该数据吗？', {
                    skin: 'layui-layer-admin',
                    shade: .1
                }, function () {
                    admin.req(getProjectUrl() + 'sysUserStuScore/delete', JSON.stringify([{'id': obj.data.id}]), function (res) {
                        layer.msg(res.message, {icon: 1, time: 1000}, function () {
                            scoreInsTb.reload();
                        });
                    }, 'post');
                });
            }
            /!* 编辑 *!/
            if (obj.event === 'scoreEdit') {
                showScoreAddOrUpdateModel(obj.data);
            }
        });

        /!* 添加学习成绩点击事件 *!/
        $('#scoreAddButton').click(function () {
            showScoreAddOrUpdateModel();
            admin.putTempData('formUserId', editData.id);
        });

        // 显示表单弹窗
        function showScoreAddOrUpdateModel(data) {
            var layIndex = admin.open({
                title: (data ? '修改' : '添加') + '学习培训成绩表',
                url: getProjectUrl() + 'sysUser/scoreForm',
                area: ['800px', '400px'],
                data: {data: data},     // 传递数据到表单页面
                end: function () {
                    var layerData = admin.getLayerData(layIndex, 'formOk');
                    if (layerData) {  // 判断表单操作成功标识
                        scoreInsTb.reload();  // 成功刷新表格
                    }
                },
                success: function (layero, dIndex) {
                    // 弹窗超出范围不出现滚动条
                    $(layero).children('.layui-layer-content').css('overflow', 'visible');
                    $(layero).find('[lay-submit]').focus();
                }
            });
        }

        /!** ************************************** 学习培训成绩相关 *************************************** **!/


        /!** ************************************** 立功经历相关 *************************************** **!/

        /!* 渲染立功经历信息表格 *!/
        var merInsTb = tableX.render({
            elem: '#merTable',
            url: getProjectUrl() + 'sysUserMer/page' + (editData ? '?userId=' + editData.id : ''),
            page: true,
            defaultToolbar: [],
            cellMinWidth: 100,
            cols: [
                [
                    {type: 'checkbox'},
                    {field: 'merTitle', title: '立功标题', sort: true, align: 'center', minWidth: 125},
                    {field: 'merContent', title: '立功内容', sort: true, minWidth: 200},
                    {field: 'merTime', title: '立功时间', sort: true, align: 'center', minWidth: 125},
                    // {field: 'status', title: '状态', sort: true, align: 'center', minWidth: 125, templet: function (d) {  return xnUtil.rendDataTableDict(d.status, 'common_status'); }},
                    {field: 'remark', title: '备注', sort: true, align: 'center', minWidth: 125},
                    {title: '操作', toolbar: '#merTableBar', align: 'center', width: 180, minWidth: 180}
                ]
            ],
            done: function (res, curr, count) {
                xnUtil.tableDone(merInsTb, res, curr, count);
            }
        });
        // 训练成绩
        upload.render({
            elem: '#importMer',
            url: getProjectUrl() + 'sysUserInfo/uploadActive?flag=3&userId='+userIds,
            accept: 'file',
            exts: 'xls|xlsx',
            done: function (res) {
                debugger;
                handleNetworkError(res);
                if (res.success) {
                    layer.msg(res.message, {icon: 1, time: 1000}, function () {
                        activityInsTb.reload();
                    });
                }
            }
        });
        /!* 立功经历信息表格工具条点击事件 *!/
        table.on('tool(merTable)', function (obj) {
            /!* 删除 *!/
            if (obj.event === 'merDelete') {
                layer.confirm('确定要操作该数据吗？', {
                    skin: 'layui-layer-admin',
                    shade: .1
                }, function () {
                    admin.req(getProjectUrl() + 'sysUserMer/delete', JSON.stringify([{'id': obj.data.id}]), function (res) {
                        layer.msg(res.message, {icon: 1, time: 1000}, function () {
                            merInsTb.reload();
                        });
                    }, 'post');
                });
            }
            /!* 编辑 *!/
            if (obj.event === 'merEdit') {
                showMerAddOrUpdateModel(obj.data);
            }
        });

        /!* 添加立功经历信息点击事件 *!/
        $('#merAddButton').click(function () {
            showMerAddOrUpdateModel();
            admin.putTempData('formUserId', editData.id);
        });

        // 显示表单弹窗
        function showMerAddOrUpdateModel(data) {
            var layIndex = admin.open({
                title: (data ? '修改' : '添加') + '用户立功经历表',
                url: getProjectUrl() + 'sysUser/merForm',
                area: ['800px', '650px'],
                data: {data: data},     // 传递数据到表单页面
                end: function () {
                    var layerData = admin.getLayerData(layIndex, 'formOk');
                    if (layerData) {  // 判断表单操作成功标识
                        merInsTb.reload();  // 成功刷新表格
                    }
                },
                success: function (layero, dIndex) {
                    // 弹窗超出范围不出现滚动条
                    $(layero).children('.layui-layer-content').css('overflow', 'visible');
                    $(layero).find('[lay-submit]').focus();
                }
            });
        }

        /!** ************************************** 立功经历相关 *************************************** **!/


        /!** ************************************** 工作经历相关 *************************************** **!/
        /!* 渲染工作经历信息表格 *!/
        var jobInsTb = tableX.render({
            elem: '#jobTable',
            url: getProjectUrl() + 'sysUserJobExperience/page' + (editData ? '?userId=' + editData.id : ''),
            page: true,
            defaultToolbar: [],
            cellMinWidth: 100,
            cols: [
                [
                    {type: 'checkbox'},
                    {field: 'jobTitle', title: '工作标题', sort: true, align: 'center', minWidth: 125},
                    {field: 'jobContent', title: '工作内容', sort: true, minWidth: 200},
                    {field: 'jobTime', title: '工作时间', sort: true, align: 'center', minWidth: 125},
                    {
                        field: 'endTime',
                        title: '工作时长',
                        sort: true,
                        align: 'center',
                        minWidth: 110
                    },
                    {
                        field: 'status',
                        title: '状态',
                        sort: true,
                        align: 'center',
                        minWidth: 125,
                        templet: function (d) {
                            return xnUtil.rendDataTableDict(d.status, 'common_status');
                        }
                    },
                    {field: 'remark', title: '备注', sort: true, align: 'center', minWidth: 125},
                    {title: '操作', toolbar: '#jobTableBar', align: 'center', width: 180, minWidth: 180}
                ]
            ],
            done: function (res, curr, count) {
                xnUtil.tableDone(jobInsTb, res, curr, count);
            }
        });
       // 训练成绩
        upload.render({
            elem: '#importWork',
            url: getProjectUrl() + 'sysUserInfo/uploadActive?flag=4&userId='+userIds,
            accept: 'file',
            exts: 'xls|xlsx',
            done: function (res) {
                debugger;
                handleNetworkError(res);
                if (res.success) {
                    layer.msg(res.message, {icon: 1, time: 1000}, function () {
                        activityInsTb.reload();
                    });
                }
            }
        });
        /!* 工作经历信息表格工具条点击事件 *!/
        table.on('tool(jobTable)', function (obj) {
            /!* 删除 *!/
            if (obj.event === 'jobDelete') {
                layer.confirm('确定要操作该数据吗？', {
                    skin: 'layui-layer-admin',
                    shade: .1
                }, function () {
                    admin.req(getProjectUrl() + 'sysUserJobExperience/delete', JSON.stringify([{'id': obj.data.id}]), function (res) {
                        layer.msg(res.message, {icon: 1, time: 1000}, function () {
                            jobInsTb.reload();
                        });
                    }, 'post');
                });
            }
            /!* 编辑 *!/
            if (obj.event === 'jobEdit') {
                showJobAddOrUpdateModel(obj.data);
            }
        });

        /!* 添加工作经历信息点击事件 *!/
        $('#jobAddButton').click(function () {
            showJobAddOrUpdateModel();
            admin.putTempData('formUserId', editData.id);
        });*/

        // 显示表单弹窗
        function showJobAddOrUpdateModel(data) {
            var layIndex = admin.open({
                title: (data ? '修改' : '添加') + '用户工作经历表',
                url: getProjectUrl() + 'sysUser/jobForm',
                area: ['800px', ''],
                data: {data: data},     // 传递数据到表单页面
                end: function () {
                    var layerData = admin.getLayerData(layIndex, 'formOk');
                    if (layerData) {  // 判断表单操作成功标识
                        jobInsTb.reload();  // 成功刷新表格
                    }
                },
                success: function (layero, dIndex) {
                    // 弹窗超出范围不出现滚动条
                    $(layero).children('.layui-layer-content').css('overflow', 'visible');
                    $(layero).find('[lay-submit]').focus();
                }
            });
        }

        /** ************************************** 工作经历相关 *************************************** **/


        if (editData !== null && editData !== undefined) {
            $('#passwordFormItemBox').remove();
            $('#rePasswordFormItemBox').remove();
            $('#activity').show();
            $('#stuExperience').show();
            $('#jobExperience').show();
            $('#merExperience').show();
            $('#scoreExperience').show();
            admin.req(getProjectUrl() + 'sysUser/detail?id=' + editData.id, function (res) {
                debugger;
                form.val('addOrUpdateForm', res.data);
                remoteDataRenderIns.setValue(res.data.sysEmpInfo.positions.map(function (item) {
                    return item.posId;
                }));
                sexDataRenderIns.setValue([res.data.sex]);
                //重载表格
                extTableData = res.data.sysEmpInfo.extOrgPos;
                insExtTb.reload({data: extTableData});
                //工号输入框回显工号
                $('#jobNumInputBox').val(res.data.sysEmpInfo.jobNum);
            });
        } else {
            $('#activity').hide();
            $('#stuExperience').hide();
            $('#jobExperience').hide();
            $('#merExperience').hide();
            $('#scoreExperience').hide();
            $('#passwordFormItemBox').removeAttr("hidden");
            $('#rePasswordFormItemBox').removeAttr("hidden");
        }

        // 表单提交事件
        form.on('submit(formSubmitBtn)', function (data) {
            layer.load(2);
            var url = editData ? getProjectUrl() + 'sysUser/edit' : getProjectUrl() + 'sysUser/add';
            var sysEmpParam = {};
            $.each(data.field, function (key, value) {
                if (key.indexOf('sysEmpParam') === 0) {
                    if (key === 'sysEmpParam.posIdList') {
                        value = value.split(',');
                    }
                    sysEmpParam[key.split('.')[1]] = value;
                    delete data.field[key];
                }
            })
            var extIds = [];
            extTableData.forEach(function (value) {
                var tempObj = {};
                tempObj.orgId = value.orgId;
                tempObj.posId = value.posId;
                extIds.push(tempObj);
            })
            sysEmpParam.orgName = orgTreeRenderIns.getValue()[0].title;
            sysEmpParam.extIds = extIds;
            data.field.sysEmpParam = sysEmpParam;
            //日期格式处理，修复空字符串转换日期导致的bug
            data.field.birthday === '' ? data.field.birthday = null : data.field.birthday = data.field.birthday;
            //日期格式处理，修复空字符串转换日期导致的bug
            data.field.entryDay === '' ? data.field.entryDay = null : data.field.entryDay = data.field.entryDay;
            //日期格式处理，修复空字符串转换日期导致的bug
            data.field.rwtime === '' ? data.field.rwtime = null : data.field.rwtime = data.field.rwtime;
            admin.req(url, JSON.stringify(data.field), function (res) {
                layer.msg(res.message, {icon: 1, time: 1000}, function () {
                    admin.putLayerData('formOk', true, '#addOrUpdateForm');
                    admin.closeDialog('#addOrUpdateForm');
                });
            }, 'post');
            return false;
        });

    });
</script>
